import {$digest, $init} from '../../lib/page.data'
import {$request, Session} from '../../lib/page.auth'

const {regeneratorRuntime} = global;
//获取应用实例
let api = require('../../utils/api.js');
let http = require('../../utils/http.js');
const app = getApp()
// pages/indexNavipage/indexNavipage.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        online_totle:0,
        min_host:api.domain,
        array2: ['全部', '男生', '女生'],
        index: 0,
        index2: 0,
        opunit: api.opunit,
        beauty: [
            {
                bName: '玖月',
                bUrl: '/images/wh1.jpg',
                tags: ['温柔', '开朗', '大神'],
                zanNum: 12,
                zt: '求单ing',
                address: '武汉',
                price: 50
            
            }
        ],
       
      
    },
  toBuyTap: function (e) {
    let id = e.currentTarget.dataset.id;
    // let uid = e.currentTarget.dataset.uid;
    wx.navigateTo({
      url: '/pages/indexBuy/indexBuy?id=' + id
    })
  },
  buyNow: function (e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/indexBuyOrder/indexBuyOrder?pid=' + id,
    })
  },
    lookDetail: function (e) {
        let id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: '/pages/indexBuy/indexBuy?id=' + id
        })
    },
    async picker1Change(e) {
        this.setData({
          
          index: e.detail.value
        });
        this.getSkillPrice();
        // var res = await this.getSkillPrice();
        // var data = JSON.parse(res.data);
        // console.log(data);
        // this.setData({priceList: data});
    },
    async picker2Change(e) {
        
        this.setData({
        
          index2: e.detail.value
          
        });
        this.getSkillPrice();
       
    },
    /* 选择器触发请求 */
    async getSkillPrice() {
        var that = this;
      var user = wx.getStorageSync('user_info');
        var data = {
            type: that.data.desc[that.data.index], 
            gender: that.data.index2, 
            sid: that.data.sid,
            lat: wx.getStorageSync('latitude'),
           lon: wx.getStorageSync('longitude'),
           user_id: user.data.id
        }
      http.get(api.new_price_list, data, function(res)
        {
            if (res.data.code == 1) 
            {
                that.setData({
                    priceList: res.data.data,
                    online_totle: res.data.data.length  
                })
            }
        }, "请求中...");

        // var res = await $request({
        //     url: api.price_list,
        //     method: 'POST',
        //     data: {type: that.data.desc[that.data.index], gender: that.data.index2, sid: that.data.sid}
        // });
        // console.log(res);
        // return res;
    },
    /**
     * 初次加载列表数据
     */
    async onLoad(options) 
    {
        var that = this;
        let id = options.id;//技能ID
        let name = options.name;//技能名称
      var user = wx.getStorageSync('user_info');
      wx.setNavigationBarTitle({
        title: name
      })
        this.setData({sid: id});
        wx.setNavigationBarTitle({title: name});

      if (options.matching==1){
        this.setData({ array: ['距离最近', '价格最低', '价格最高', '最新加入', '热门推荐']});
        this.setData({ desc: ['distance', 'endprice', 'hightprice', 'new_join', 'hot']});
          var type = 'distance';
        }else{
          this.setData({ array: ['热门推荐', '价格最低', '价格最高', '最新加入'] });
          this.setData({ desc: ['hot', 'endprice', 'hightprice', 'new_join'] });
          var type = 'hot';
        }
      http.get(api.new_price_list, { sid: options.id, lat: wx.getStorageSync('latitude'), lon: wx.getStorageSync('longitude'), type: type, gender:0,user_id:user.data.id}, function(res)
        {
            if (res.data.code == 1) 
            {
                that.setData({
                    priceList: res.data.data,
                    online_totle: res.data.data.length
                })
            }
        }, "请求中...");
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})